package com.onairm.baselibrary.net;



import com.onairm.baselibrary.utils.TipToast;
import com.onairm.baselibrary.utils.Utils;

import rx.Subscriber;

/**
 * Created by apple on 17/11/2.
 */

public abstract class HttpBaseResultSubscriber<T extends BaseData> extends Subscriber<T> {
    @Override
    public void onCompleted() {

    }

    @Override
    public void onStart() {
        super.onStart();
        if (!Utils.isNetAvailable()){
            TipToast.longTip("连接失败");
        }
    }

    @Override
    public void onError(Throwable e) {
            onHttpError(e);
    }

    @Override
    public void onNext(T tBaseData) {
            if (tBaseData.getStatusCode()==0){
                onSuccess(tBaseData);
            }else if(tBaseData.getStatusCode()==2002){
               // TipToast.shortTip("账号过期");
            }else {
               onHttpError(new Throwable(tBaseData.getMessage()));
            }
    }


    public abstract void onSuccess(T t);


    public abstract void onHttpError(Throwable throwable);

}
